<html>
<head><meta charset="utf-8"><title>Layout of built in type (llvm codegen) · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Layout.20of.20built.20in.20type.20(llvm.20codegen).html">Layout of built in type (llvm codegen)</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="246722129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Layout%20of%20built%20in%20type%20%28llvm%20codegen%29/near/246722129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kjetil Kjeka <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Layout.20of.20built.20in.20type.20(llvm.20codegen).html#246722129">(Jul 21 2021 at 13:51)</a>:</h4>
<p>After definingt a new built in type in the compiler, I'm getting an error message <code>error: internal compiler error: compiler/rustc_codegen_llvm/src/context.rs:801:17: failed to get layout for </code>Test<code>: the type </code>&amp;[_[u32]]<code> has an unknown layout</code> even after defining the layout of the type in <code>rustc_middle::ty::layout</code>. I'm not sure if there are any other places the layout needs to be defined or if it is somehow related to the layout of the reference being larger than 2 pointer widths. I would greatly appreciate some guidance. </p>
<p><a href="/user_uploads/4715/tTBTTumPat3iIftusxJCg39o/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/tTBTTumPat3iIftusxJCg39o/image.png" title="image.png"><img src="/user_uploads/4715/tTBTTumPat3iIftusxJCg39o/image.png"></a></div><p>I'm doing an experimenting in adding a new built in (DST) type to the compiler. The type is an array view (of N-dimensions) that owns non-contigous (but structured) memory. A reference to such type needs to contain more than one pointer width of metadata. An array view of N-dimensions needs to contain both N dimensions of stride and length info, in total 2xN ptr width integers of data. The layout of a reference to a view (currently: <code>&amp;[T[DIM]]</code> is defined as such:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">Layout</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">variants</span>: <span class="nc">Variants</span>::<span class="n">Single</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">index</span>: <span class="nc">VariantIdx</span>::<span class="n">new</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="p">},</span><span class="w"></span>
<span class="w">    </span><span class="n">fields</span>: <span class="nc">FieldsShape</span>::<span class="n">Arbitrary</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">offsets</span>: <span class="nc">vec</span><span class="o">!</span><span class="p">[</span><span class="n">Size</span>::<span class="n">ZERO</span><span class="p">,</span><span class="w"> </span><span class="n">len_offset</span><span class="p">,</span><span class="w"> </span><span class="n">stride_offset</span><span class="p">],</span><span class="w"></span>
<span class="w">        </span><span class="n">memory_index</span>: <span class="nc">vec</span><span class="o">!</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">],</span><span class="w"></span>
<span class="w">    </span><span class="p">},</span><span class="w"></span>
<span class="w">    </span><span class="n">abi</span>: <span class="nc">Abi</span>::<span class="n">Aggregate</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">sized</span>: <span class="nc">true</span><span class="w"> </span><span class="p">},</span><span class="w"></span>
<span class="w">    </span><span class="n">largest_niche</span>: <span class="nb">None</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">align</span>: <span class="nc">metadata_element_align</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">size</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>This work is to further investigate the topics in this thread: <a href="https://internals.rust-lang.org/t/should-array-view-be-an-internal-type/14983">https://internals.rust-lang.org/t/should-array-view-be-an-internal-type/14983</a></p>



<a name="246759168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Layout%20of%20built%20in%20type%20%28llvm%20codegen%29/near/246759168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kjetil Kjeka <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Layout.20of.20built.20in.20type.20(llvm.20codegen).html#246759168">(Jul 21 2021 at 18:24)</a>:</h4>
<p>I think I (at least partially) solved my own problem. It looks like its related to the dimension not being possible to evaluate as a const. More specifically the <code>rustc_middle::ty::consts::try_eval_usize</code> function.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>